// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement
{
	public sealed partial class IndexSettingBlocks
	{
		[JsonInclude]
		[JsonPropertyName("metadata")]
		public bool? Metadata { get; set; }

		[JsonInclude]
		[JsonPropertyName("read")]
		public bool? Read { get; set; }

		[JsonInclude]
		[JsonPropertyName("read_only")]
		public bool? ReadOnly { get; set; }

		[JsonInclude]
		[JsonPropertyName("read_only_allow_delete")]
		public bool? ReadOnlyAllowDelete { get; set; }

		[JsonInclude]
		[JsonPropertyName("write")]
		public Union<bool?, string?>? Write { get; set; }
	}

	public sealed partial class IndexSettingBlocksDescriptor : SerializableDescriptorBase<IndexSettingBlocksDescriptor>
	{
		internal IndexSettingBlocksDescriptor(Action<IndexSettingBlocksDescriptor> configure) => configure.Invoke(this);
		public IndexSettingBlocksDescriptor() : base()
		{
		}

		private bool? MetadataValue { get; set; }

		private bool? ReadValue { get; set; }

		private bool? ReadOnlyValue { get; set; }

		private bool? ReadOnlyAllowDeleteValue { get; set; }

		private Union<bool?, string?>? WriteValue { get; set; }

		public IndexSettingBlocksDescriptor Metadata(bool? metadata = true)
		{
			MetadataValue = metadata;
			return Self;
		}

		public IndexSettingBlocksDescriptor Read(bool? read = true)
		{
			ReadValue = read;
			return Self;
		}

		public IndexSettingBlocksDescriptor ReadOnly(bool? readOnly = true)
		{
			ReadOnlyValue = readOnly;
			return Self;
		}

		public IndexSettingBlocksDescriptor ReadOnlyAllowDelete(bool? readOnlyAllowDelete = true)
		{
			ReadOnlyAllowDeleteValue = readOnlyAllowDelete;
			return Self;
		}

		public IndexSettingBlocksDescriptor Write(Union<bool?, string?>? write)
		{
			WriteValue = write;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (MetadataValue.HasValue)
			{
				writer.WritePropertyName("metadata");
				writer.WriteBooleanValue(MetadataValue.Value);
			}

			if (ReadValue.HasValue)
			{
				writer.WritePropertyName("read");
				writer.WriteBooleanValue(ReadValue.Value);
			}

			if (ReadOnlyValue.HasValue)
			{
				writer.WritePropertyName("read_only");
				writer.WriteBooleanValue(ReadOnlyValue.Value);
			}

			if (ReadOnlyAllowDeleteValue.HasValue)
			{
				writer.WritePropertyName("read_only_allow_delete");
				writer.WriteBooleanValue(ReadOnlyAllowDeleteValue.Value);
			}

			if (WriteValue is not null)
			{
				writer.WritePropertyName("write");
				JsonSerializer.Serialize(writer, WriteValue, options);
			}

			writer.WriteEndObject();
		}
	}
}